package controllers;

import dao.ITheatreDao;
import models.User;
import play.mvc.Before;
import play.mvc.Controller;
import serviceImpl.TheatreDaoImpl;

/**
 * Created by 国彬 on 2016/7/3.
 */
public class TheatreAction extends Controller {

    static ITheatreDao theatreDao = new TheatreDaoImpl();
    @Before
    static void checkLogin(){
        renderArgs.put("cxt",request.host);
        if(session.get("user")!=null){
            renderArgs.put("user", User.findById(session.get("user")));
        }
    }

    /**
     * 分页查询影院
     */
    public static void getTheatresByCity(){
        String city = request.params.get("city");
        int page = request.params.get("page",Integer.class);
        int length = request.params.get("length",Integer.class);
        String area = request.params.get("area");
        WebService.wsOk(theatreDao.findTheatresByCity(city, page, length,area));
    }

    /**
     * 分页查询影院，加关键字模糊查询
     */
    public static void getTheatresByCityWithKeyWord(){
        String city = request.params.get("city");
        int page = request.params.get("page",Integer.class);
        int length = request.params.get("length",Integer.class);
        String area = request.params.get("area");
        String keyWord = request.params.get("keyWord");
        WebService.wsOk(theatreDao.findTheatresByCityWithKeyWord(city, page, length,area,keyWord));
    }

    /**
     * 查询影院详细信息
     * @param id
     */
    public static void theatreDetail(String id){
        WebService.wsOk(theatreDao.findDetailById(id));
    }
}
